﻿using Apache.IoTDB;
using Iot.TimingDatabase.EnumTypeCache;
using Iot.TimingDatabase.Event;
using Iot.TimingDatabase.Helper;
using Microsoft.Extensions.DependencyInjection;

namespace Iot.TimingDatabase;

public static class Injection
{
    /// <summary>
    ///     /向IServiceCollection中添加TimingDatabase服务
    /// </summary>
    /// <param name="services"></param>
    /// <param name="host"></param>
    /// <param name="port"></param>
    /// <param name="poolSize"></param>
    /// <returns></returns>
    public static IServiceCollection AddTimingDatabase<T>(this IServiceCollection services, string host = "localhost",
        int port = 6667, int poolSize = 8)
        where T : class, IEnumTypeCache
    {
        services.AddSingleton(new SessionPool.Builder().SetHost(host).SetPort(port).SetPoolSize(poolSize).Build());
        services.AddSingleton<IEnumTypeCache, T>();
        services.AddSingleton<IotDbConversion>();
        services.AddSingleton<IotDbQuery>();
        return services;
    }

    /// <summary>
    ///     /向IServiceCollection中添加TimingDatabase服务
    /// </summary>
    /// <param name="services"></param>
    /// <returns></returns>
    public static IServiceCollection AddTimingDatabase(this IServiceCollection services)
    {
        return AddTimingDatabase<EnumTypeCacheSqlIet>(services);
    }
}